package com.linjiahao.nettyOne.handler;

import com.alibaba.fastjson.JSON;
import com.linjiahao.nettyOne.server.SendMessage;
import com.linjiahao.servicebase.vo.NettyMessageVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.net.UnknownHostException;

/**
 * @ClassName RabbitReceiver
 * @Description: rabbit消息监听消费处理
 * @Author linjiahao
 * @Date 26/12/2021
 **/
@Component
@Slf4j
public class RabbitReceiver {

    @Resource
    private SendMessage sendMessage;

    @RabbitListener(queues = "#{autoDeleteQueue0.name}")
    public void receiver0(String message) throws UnknownHostException {
        log.info("本次mq监听到的消息为：{}",message);
        NettyMessageVO nettyMessageVO = JSON.parseObject(message, NettyMessageVO.class);
        sendMessage.send(null,nettyMessageVO,Boolean.TRUE);
    }

}
